package arrayList;

import dome2.MyArray;

/**
 * Created with IntelliJ IDEA.
 * Description: 顺序表代码测试
 * User: 王圆豪
 * Date: 2024-07-18
 * Time: 20:51
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("--------(1)创建新的线性表-------");
        MyArraylist<Integer> arr1 = new MyArraylist<>();
        System.out.println(arr1);

        System.out.println("--------(2)用指定数组创建线性表-------");
        MyArraylist<Integer> arr2 = new MyArraylist<>();
        Integer[] s = new Integer[]{1,2,3,4,5};
        arr2.create(s);
        System.out.println(arr2);

        System.out.println("--------(3)求指定序号元素-------");
        System.out.println("序号为2的元素是：" + arr2.get(2));
//        System.out.println("序号为6的元素是：" + arr2.get(6));

        System.out.println("--------(4)设置指定序号元素-------");
        arr2.set(2, 9);
        System.out.println("把序号为2的元素设置为：" + arr2.get(2));
//        arr2.set(6, 2);
//        System.out.println("把序号为6的元素设置为：" + arr2.get(6));

        System.out.println("--------(5)求元素的序号-------");
        System.out.println("数字9的位置：" + arr2.indexOf(9));
//        System.out.println("数字22的位置：" + arr2.indexOf(22));

        System.out.println("--------(6)插入元素-------");
        arr2.add(3,65);
//        arr2.add(99,3);
        System.out.println(arr2);

        System.out.println("--------(7)删除元素-------");
        arr2.remove(9);
        arr2.add(2, 178);
        System.out.println(arr2);

        System.out.println("--------(8)插入元素  异常-------");
        arr2.add(99, 2);
        System.out.println(arr2);

        System.out.println("--------(9)设置长度-------");
        arr2.setSize(2);
        System.out.println("长度为2的线性表：" + arr2);
    }
}
